package hit.edu.zjc.parsers;
//对ScanOperator的一次尝试。

import hit.edu.zjc.Tool.ObjectConvert;

import java.io.DataOutput;
import java.io.IOException;

import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
import edu.uci.ics.hyracks.dataflow.common.data.parsers.IValueParser;
import edu.uci.ics.hyracks.dataflow.common.data.parsers.IValueParserFactory;
/*
 * This Class AFK
 * */
public class ByteParserFactory implements IValueParserFactory {
    public static final IValueParserFactory INSTANCE = new ByteParserFactory();

    private static final long serialVersionUID = 1L;

    private ByteParserFactory() {
    }

    @Override
    public IValueParser createValueParser() {
        return new IValueParser() {
            @Override
            public void parse(char[] buffer, int start, int length, DataOutput out) throws HyracksDataException {
                //String s = String.valueOf(buffer, start, length);
                try {
                	byte[] bytes=ObjectConvert.Chars2Bytes(buffer, start, length);
                   out.write(bytes);
                } catch (NumberFormatException e) {
                    throw new HyracksDataException(e);
                } catch (IOException e) {
                    throw new HyracksDataException(e);
                }
            }
        };
    }
}